home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / UUPC3 / MAC_SPEC / UNIX_LIB / CHDIR.C next >
C/C++ Source or Header  |  1991-12-04  |  2KB  |  89 lines

  1. #include "host.h"
  2.  
  3. #ifdef THINK_C
  4. # include "unixlibproto.h"
  5. #endif THINK_C
  6.  
  7. #include <string.h>
  8. #ifdef    TEST
  9. #    include    <stdio.h>
  10. #endif    TEST
  11. #ifndef NULL
  12. #define NULL 0L
  13. #endif
  14.  
  15. chdir( path )
  16. char * path;
  17. {
  18.  
  19.     char         npath[255];
  20.     CInfoPBRec    cpb;
  21.     WDPBRec        wdpb;
  22.     int            vRef;
  23.  
  24.     /* get default WD id */
  25.     (void)GetVol((StringPtr)npath, &vRef);
  26.     
  27.     /* convert to Mac-style pathname */
  28.     cnvMac( path, npath );
  29.  
  30. #ifdef NOTDEF
  31.     cpb.dirInfo.ioVRefNum = 0;
  32.     cpb.dirInfo.ioNamePtr = (StringPtr)CtoPstr(npath);
  33.     cpb.dirInfo.ioFDirIndex = 0;
  34.     cpb.dirInfo.ioDrDirID = 0L;
  35.  
  36. #ifdef TEST
  37.     fprintf( stderr, "opendir: %s\n", buf );
  38. #endif
  39.  
  40.     if (PBGetCatInfo( &cpb, 0 ) != noErr ) {
  41. #ifdef TEST
  42.         fprintf( stderr, "setdir: PBGetCatInfo %d\n", err );
  43. #endif
  44.         return((int)NULL);
  45.     }
  46.  
  47. #ifdef THINK_C
  48.     memset((char *)(&wdpb), (int)NULL, (size_t)sizeof(wdpb));
  49. #else THINK_C
  50.     repmem((char *)&wdpb, "", 1, sizeof(wdpb));
  51. #endif THINK_C
  52.     wdpb.ioVRefNum = cpb.dirInfo.ioVRefNum;
  53.     wdpb.ioWDProcID = 'UUPC';
  54.     wdpb.ioWDDirID = cpb.dirInfo.ioDrDirID;
  55.     if (PBOpenWD(&wdpb, FALSE) != noErr) {
  56.         return((int)NULL);
  57.     }
  58.     if (SetVol((int)NULL, wdpb.ioVRefNum) != noErr) {
  59.         return((int)NULL);
  60.     }
  61. #else
  62.     memset((char *)(&wdpb), (int)NULL, (size_t)sizeof(wdpb));
  63.     wdpb.ioNamePtr = (StringPtr)CtoPstr(npath);
  64.     if (PBHSetVol(&wdpb, FALSE) != noErr) {
  65.         return((int)NULL);
  66.     }
  67. #endif
  68.  
  69. #ifdef TEST
  70.     fprintf( stderr, "opendir: %s\n", npath );
  71. #endif
  72. #if DEBUG
  73.     printf("wd.ioVRefNum = %x, wd.ioWDDirID = %lx\n", wd.ioVRefNum, wd.ioWDDirID);
  74. #endif
  75.     return(noErr);    
  76. }
  77.  
  78. #ifdef TEST
  79. main()
  80. {
  81.     char command[100];
  82.  
  83.     gets( command );
  84.     fprintf( stderr, "%d\n", chdir( command ));
  85. }
  86.  
  87. #endif
  88.  
  89.